/**
 * 卖给上游页面
 */


var orderStatus;
// 选择发货状态
function chooseClick(index) {
    orderStatus = index;
}


var newTime = timeAll(); // ?? $里面是否能访问的奥


// 查询方法
function gerDiffiendOrder() {
    var beginTimeStr = document.getElementById("showDate").innerHTML;
    var endADateStr = document.getElementById("endADate").innerHTML;
    if (beginTimeStr == '选择开始日期') {
        beginTimeStr = '';
    } else {
        beginTimeStr = beginTimeStr.replace('年', '-');
        beginTimeStr = beginTimeStr.replace('月', '-');
        beginTimeStr = beginTimeStr.replace('日', '');
    }

    if (endADateStr == '选择结束日期') {
        endADateStr = '';
    } else {
        endADateStr = endADateStr.replace('年', '-');
        endADateStr = endADateStr.replace('月', '-');
        endADateStr = endADateStr.replace('日', '');
    }

    var expressNum = $("#expressNum").val();

    console.log(beginTimeStr);
    console.log(endADateStr);
    console.log(expressNum);
    console.log(orderStatus);

    //  拼接，加密，变大写，传值
    var timestamp = 'timeStamp:' + newTime + 'BM' + 'pageNum:' + 1 + 'BM' + 'pageSize:' + 100 + 'BM' + 'startDate:' + beginTimeStr + 'BM' + 'endDate:' + endADateStr + 'BM' + 'orderStatus:' + orderStatus + 'BM' + 'expressNum:' + expressNum + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    // 发送请求
    $.ajax({
        type: 'get',
        url: webUrl3 + 'store/paltformTransaction/getOrderListByCondition',
        data: {
            'timeStamp': newTime,
            'sign': signs,
            'pageNum': 1,// 等分页封装好在上传；下拉加载更多
            'pageSize': 100,
            'startDate': beginTimeStr,
            'endDate': endADateStr,
            'orderStatus': orderStatus,
            'expressNum': expressNum,
        },
        dataType: 'JSON',
        async: false,
        success: function (data) {
            if (data.status == 200) {
                result='';
                $("#ulList").html(data);
                if ( data.data.length>0){
                    //  拼接展示不同状态订单信息。确认收货；将orderID 作为参数传过去
                    for (var i = 0; i < data.data.length; i++) {
                        var item = data.data[i];
                        var orderList = '<li class="nav-item">' +
                            '<div class="IndexDiv">' +
                            '<div class="timeDiv">' +
                            '<div class="time">' +item.updateDate+ '</div>' +
                            '<div class="sendtype">' +item.orderStatusName+ '</div>' +
                            '</div>' +
                            '<div class="timeDiv">' +
                            '<div class="iphoneName">' +item.productName+ '</div>' +
                            '<div class="iemDiv">' + 'ime号:' + item.imei + '</div>' +
                            '</div>' +
                            '<div class="timeDiv">下单时间：' + item.storeCreateDate + '</div>' +
                            '<div class="timeDiv">快递单号：' + item.expressNum + '</div>' +
                            '</div>' +
                            '<a href="javascript:;">' +
                            '<span>估价单</span>' +
                            '<i class="my-icon nav-more">' +
                            '</i>' +
                            '<span class="nav-more2">收起</span>' +
                            '</a>' +
                            '<ul>';
                        if (item.orderStatus == 400){
                            var jtem2=item.storeProductDetail.attrList;
                            var jtem3=item.storeProductDetail.problemList;
                            orderList=orderList+'<li style="width: 100%;height:40px;line-height:40px;background: #3ad2c3;color: white"> ' +
                                '<div class="jtem3">' +'机况选项'+'</div><div class="jtem3">'  + '商家检测机况'+ '</div>' +
                                '</li>';
                            for (var j=0;j<jtem2.length;j++){
                                if (j%2==0){
                                    orderList=orderList+'<li> ' +
                                        '<div class="jtem3">' + jtem2[j].attrCategoryName+'</div><div class="jtem3">'  + jtem2[j].attrName+ '</div>' +
                                        '</li>';
                                }else {
                                    orderList=orderList+'<li style="background: #F1F1F1"> ' +
                                        '<div class="jtem3">' + jtem2[j].attrCategoryName+'</div><div class="jtem3">'  + jtem2[j].attrName+ '</div>' +
                                        '</li>';
                                }
                            }
                            for (var h=0;h<jtem3.length;h++){
                                if (h%2==0){
                                    orderList=orderList+'<li> ' +
                                        '<div class="jtem3">' + jtem3[h].problemCategoryName +'</div><div class="jtem3">'  + jtem3[h].problemName+ '</div>' +
                                        '</li>';
                                }else {
                                    orderList=orderList+'<li style="background: #F1F1F1"> ' +
                                        '<div class="jtem3">' + jtem3[h].problemCategoryName +'</div><div class="jtem3">'  + jtem3[h].problemName+ '</div>' +
                                        '</li>';
                                }

                            }
                            orderList=orderList+ '</ul>' +
                                '<div class="pricesDiv">预估价：<span style="color: #ff3b6a">' +"￥"+item.estimatedPrice + '</span></div>' +
                                '<div class="btnDiv">' +
                                '<div class="btn_item" onclick=cancleGoodClick(\"' + item.orderId + '\")>取消发货</div>' +
                                '<div class="btn_item2" onclick=sureGoodClick(\"' + item.orderId + '\")>确定发货</div>' +
                                '</div>';

                        }else {

                        }
                        orderList=orderList+
                            '</li>' +
                            '<div class="lineDiv"></div>';
                        $('#ulList').append(orderList)
                    }
                }else {
                   var orderList='<div style="width: 100%;height: 450px;line-height: 450px;text-align: center">暂时还没有订单</div>';
                   $('#ulList').html(orderList);
                }
            } else if (data.status == 300) {
                document.location.href = '../../html/login.html';
            } else {
                alert(data.msg)
            }
        }
    })
}


// 确定发货
function sureGoodClick(id) {
    document.location.href = '../../sellUpstream/sureGood/sureGood.html?star='+id;
}



// 批量发货
function batchDelivery() {
    document.location.href = '../../sellUpstream/batchDelivery/batchDelivery.html?orderStatus='+ "410";
}

// 批量取消
function skipAbolish() {
    document.location.href = '../../sellUpstream/batchDelivery/batchDelivery.html?orderStatus='+ "492";
}

// 跳转添加订单
function skipAdd() {
    document.location.href = '../addOrder/addOrder.html';
}







function cancleGoodClick(id) {
    var timeStamp = "timeStamp:" + newTime + "BM"  + "orderIds:" + id + "BM" + "orderStatus:" + '492' + "BM" ;
    var signs = md5(timeStamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: "post",
        url: webUrl + "paltformTransaction/postBatchDeliveryOrCancle",
        data: {
            "timeStamp": newTime,
            "orderIds": id,
            "orderStatus": '492',
            "sign": signs,
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            if (data.status == 200) {
                gerDiffiendOrder();
            } else if (data.status == 300) {
                document.location.href = '../../html/login.html';
            } else if (data.status == 500) {
                dialog(data.msg);
            }
        },
        error: function (data) {
            //弹出报错内容　　
            dialog("服务器异常")
        }
    })
}














//  查看物流信息   点击弹框；物流信息页面展示
function lookExpress(id) {
    var newTime = timeAll(); // 定义一个时间戳
    //  拼接，加密，变大写，传值
    var timestamp = 'timeStamp:' + newTime + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    // 发送请求
    $.ajax({
        type: 'get',
        url: webUrl3 + 'store/paltformTransaction/getLogisticsInfoLis',
        data: {
            'timeStamp': newTime,
            'sign': signs,
            'orderId': id,
        },
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data)
            if (data.status == 200) {
                //  成功弹框展示信息；处理数据，展示物流信息

            } else if (data.status == 300) {
                // document.location.href = '../html/login.html';
            } else {
                alert(data.msg)
            }
        }
    })
}

//  获取总价及邮寄信息
function mailInformation(id) {
    var newTime = timeAll(); // 定义一个时间戳
    //  拼接，加密，变大写，传值
    var timestamp = 'timeStamp:' + newTime + 'BM' + 'orderId:' + id + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    // 发送请求
    $.ajax({
        type: 'get',
        url: webUrl3 + 'store/paltformTransaction/getLogisticsInfoLis',
        data: {
            'timeStamp': newTime,
            'sign': signs,
            'orderId': id, // 英文逗号分割 最后一位没有都好；muchorderID
        },
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data)
            if (data.status == 200) {
                //  查看物流消息；成功后弹框；调获取总价及邮寄信息的接口

            } else if (data.status == 300) {
                // document.location.href = '../html/login.html';
            } else {
                alert(data.msg)
            }
        }
    })
}
